<?php

namespace App\Http\Middleware;

use App\Enum\TravelEnum;
use Closure;
use Illuminate\Support\Facades\Log;

class BackendAuth
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        Log::notice('coming from backend, url=>'.$request->path());
        $appId = $request->header('App-Platform-Id');
        if (empty($appId) || $appId != TravelEnum::PLATFORM_BACKEND) {
            return fail(10010, '来源出错：999');
        }
        if( !isset($request->from) || $request->from != 'backend' )
            return fail(404,'缺少参数[from]',[]);

        Log::notice('coming from backend, auth passed.........');
        return $next($request);
    }
}
